from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-14 14:04:18.690492
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 14, Jan, 2022
Time: 14:04:24
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7058
Nobs: 536.000 HQIC: -48.1437
Log likelihood: 6222.97 FPE: 9.31661e-22
AIC: -48.4251 Det(Omega_mle): 7.88873e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377075 0.071359 5.284 0.000
L1.Burgenland 0.101532 0.042841 2.370 0.018
L1.Kärnten -0.113105 0.022127 -5.112 0.000
L1.Niederösterreich 0.187215 0.089113 2.101 0.036
L1.Oberösterreich 0.115512 0.088646 1.303 0.193
L1.Salzburg 0.267193 0.045268 5.902 0.000
L1.Steiermark 0.026712 0.059586 0.448 0.654
L1.Tirol 0.105971 0.048042 2.206 0.027
L1.Vorarlberg -0.077196 0.042523 -1.815 0.069
L1.Wien 0.015329 0.078336 0.196 0.845
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064482 0.156193 0.413 0.680
L1.Burgenland -0.043579 0.093771 -0.465 0.642
L1.Kärnten 0.040277 0.048432 0.832 0.406
L1.Niederösterreich -0.206329 0.195053 -1.058 0.290
L1.Oberösterreich 0.453405 0.194032 2.337 0.019
L1.Salzburg 0.286652 0.099085 2.893 0.004
L1.Steiermark 0.111431 0.130423 0.854 0.393
L1.Tirol 0.307587 0.105156 2.925 0.003
L1.Vorarlberg 0.020682 0.093077 0.222 0.824
L1.Wien -0.025481 0.171464 -0.149 0.882
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195782 0.036473 5.368 0.000
L1.Burgenland 0.091746 0.021897 4.190 0.000
L1.Kärnten -0.007583 0.011310 -0.671 0.503
L1.Niederösterreich 0.234551 0.045548 5.150 0.000
L1.Oberösterreich 0.166437 0.045309 3.673 0.000
L1.Salzburg 0.039884 0.023138 1.724 0.085
L1.Steiermark 0.025245 0.030456 0.829 0.407
L1.Tirol 0.081974 0.024556 3.338 0.001
L1.Vorarlberg 0.054715 0.021735 2.517 0.012
L1.Wien 0.118809 0.040039 2.967 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127165 0.036456 3.488 0.000
L1.Burgenland 0.041020 0.021887 1.874 0.061
L1.Kärnten -0.014184 0.011304 -1.255 0.210
L1.Niederösterreich 0.169928 0.045527 3.733 0.000
L1.Oberösterreich 0.334708 0.045288 7.391 0.000
L1.Salzburg 0.104255 0.023127 4.508 0.000
L1.Steiermark 0.109136 0.030441 3.585 0.000
L1.Tirol 0.091499 0.024544 3.728 0.000
L1.Vorarlberg 0.055529 0.021725 2.556 0.011
L1.Wien -0.019640 0.040021 -0.491 0.624
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.106689 0.069277 1.540 0.124
L1.Burgenland -0.040421 0.041591 -0.972 0.331
L1.Kärnten -0.045425 0.021481 -2.115 0.034
L1.Niederösterreich 0.142892 0.086512 1.652 0.099
L1.Oberösterreich 0.172576 0.086059 2.005 0.045
L1.Salzburg 0.278992 0.043947 6.348 0.000
L1.Steiermark 0.063444 0.057847 1.097 0.273
L1.Tirol 0.153294 0.046640 3.287 0.001
L1.Vorarlberg 0.095290 0.041282 2.308 0.021
L1.Wien 0.076650 0.076050 1.008 0.314
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.088358 0.053822 1.642 0.101
L1.Burgenland 0.021059 0.032312 0.652 0.515
L1.Kärnten 0.052192 0.016689 3.127 0.002
L1.Niederösterreich 0.189564 0.067212 2.820 0.005
L1.Oberösterreich 0.327789 0.066860 4.903 0.000
L1.Salzburg 0.038341 0.034143 1.123 0.261
L1.Steiermark -0.001982 0.044942 -0.044 0.965
L1.Tirol 0.123723 0.036235 3.414 0.001
L1.Vorarlberg 0.063685 0.032073 1.986 0.047
L1.Wien 0.098567 0.059084 1.668 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164199 0.065240 2.517 0.012
L1.Burgenland 0.009230 0.039167 0.236 0.814
L1.Kärnten -0.065060 0.020229 -3.216 0.001
L1.Niederösterreich -0.110099 0.081471 -1.351 0.177
L1.Oberösterreich 0.219981 0.081045 2.714 0.007
L1.Salzburg 0.049911 0.041386 1.206 0.228
L1.Steiermark 0.252782 0.054476 4.640 0.000
L1.Tirol 0.496550 0.043922 11.305 0.000
L1.Vorarlberg 0.065812 0.038877 1.693 0.090
L1.Wien -0.079375 0.071618 -1.108 0.268
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166410 0.072118 2.307 0.021
L1.Burgenland -0.008943 0.043296 -0.207 0.836
L1.Kärnten 0.062551 0.022362 2.797 0.005
L1.Niederösterreich 0.174397 0.090061 1.936 0.053
L1.Oberösterreich -0.065885 0.089589 -0.735 0.462
L1.Salzburg 0.208475 0.045750 4.557 0.000
L1.Steiermark 0.137059 0.060219 2.276 0.023
L1.Tirol 0.055780 0.048553 1.149 0.251
L1.Vorarlberg 0.143603 0.042976 3.341 0.001
L1.Wien 0.129458 0.079169 1.635 0.102
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.396851 0.042138 9.418 0.000
L1.Burgenland -0.003011 0.025298 -0.119 0.905
L1.Kärnten -0.020599 0.013066 -1.577 0.115
L1.Niederösterreich 0.201654 0.052621 3.832 0.000
L1.Oberösterreich 0.240769 0.052346 4.600 0.000
L1.Salzburg 0.035176 0.026731 1.316 0.188
L1.Steiermark -0.017210 0.035186 -0.489 0.625
L1.Tirol 0.086615 0.028369 3.053 0.002
L1.Vorarlberg 0.050068 0.025110 1.994 0.046
L1.Wien 0.033268 0.046258 0.719 0.472
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.032955 0.096526 0.159727 0.136571 0.084313 0.080280 0.024936 0.206807
Kärnten 0.032955 1.000000 -0.027754 0.132487 0.047487 0.082608 0.446798 -0.071289 0.092717
Niederösterreich 0.096526 -0.027754 1.000000 0.306577 0.122778 0.262326 0.062272 0.154793 0.277860
Oberösterreich 0.159727 0.132487 0.306577 1.000000 0.217425 0.291137 0.168837 0.130466 0.229714
Salzburg 0.136571 0.047487 0.122778 0.217425 1.000000 0.125712 0.084599 0.106915 0.125857
Steiermark 0.084313 0.082608 0.262326 0.291137 0.125712 1.000000 0.134726 0.101444 0.025360
Tirol 0.080280 0.446798 0.062272 0.168837 0.084599 0.134726 1.000000 0.062822 0.146497
Vorarlberg 0.024936 -0.071289 0.154793 0.130466 0.106915 0.101444 0.062822 1.000000 -0.008714
Wien 0.206807 0.092717 0.277860 0.229714 0.125857 0.025360 0.146497 -0.008714 1.000000